package com.suez.eimsserver.runnable;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

import com.suez.eimsserver.controller.ReceiveMsgController;
import com.suez.eimsserver.entity.Protocol;

public class ServerRunnable implements Runnable{
	private Socket socket;
	private OutputStream os;
	
	public ServerRunnable(Socket socket){
		this.socket=socket;
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		InputStream is;
		try {
			while(true){
				is = socket.getInputStream();
				os = socket.getOutputStream();
				
				ObjectInputStream ois = new ObjectInputStream(is);
				Protocol protocol = (Protocol) ois.readObject();

				System.out.println("客户端输入的指令为："+protocol.getAction());
				Protocol protocol2=ReceiveMsgController.receive(protocol);
				
				ObjectOutputStream oos = new ObjectOutputStream(os);
				oos.writeObject(protocol2);
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
